namespace SimpleWebServices.Configuration
{
    using System.Xml.XPath;
    using Xunit;

    public sealed class RootSettingsFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<RootSettings>()
                .DerivesFrom<object>()
                .IsConcreteClass()
                .IsSealed()
                .HasDefaultConstructor()
                .XmlRoot("root")
                .Result);
        }

        [Fact]
        public void deserialize()
        {
            RootSettings actual = "<root redirect='home' />".Deserialize<RootSettings>();

            Assert.Equal<string>("home", actual.Redirect);
        }

        [Fact]
        public void deserializeEmpty()
        {
            RootSettings actual = "<root />".Deserialize<RootSettings>();

            Assert.Null(actual.Redirect);
        }

        [Fact]
        public void serialize()
        {
            RootSettings obj = new RootSettings
            {
                Redirect = "home"
            };

            XPathNavigator navigator = obj.Serialize().CreateNavigator();

            Assert.True((bool)navigator.Evaluate("1=count(/root[@redirect='home'])"));
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new RootSettings());
        }

        [Fact]
        public void prop_Redirect()
        {
            Assert.True(new PropertyExpectations(typeof(RootSettings).GetProperty("Redirect"))
                .XmlAttribute("redirect")
                .IsAutoProperty<string>()
                .Result);
        }
    }
}